package cn.walls1717.wallsmall.order.web;

import cn.walls1717.wallsmall.order.config.AlipayTemplate;
import cn.walls1717.wallsmall.order.pojo.vo.PayVO;
import cn.walls1717.wallsmall.order.service.OrderService;
import com.alipay.api.AlipayApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 支付
 *
 * @author walls1717
 * @since 2022/11/23 22:48
 **/
@Controller
@Slf4j
public class PayWebController {
    @Resource
    private AlipayTemplate alipayTemplate;
    @Resource
    private OrderService orderService;

    /** 使用支付宝支付 */
    @GetMapping(value = "/payOrder", produces = "text/html")
    @ResponseBody
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVO payVO = orderService.getOrderPay(orderSn);
        String pay = alipayTemplate.pay(payVO);
        log.info("pay -> {}", pay);
        return pay;
    }
}
